home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / PKTSTAT.ASM < prev    next >
Assembly Source File  |  1991-03-25  |  5KB  |  259 lines

  1. version    equ    1
  2.  
  3. ;  Russell Nelson, Clarkson University.  September 14, 1989
  4. ;  Copyright, 1989, Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    80h
  25. phd_dioa    label    byte
  26.  
  27.     org    100h
  28. start:
  29.     jmp    start_1
  30.  
  31. copyleft_msg    label    byte
  32.  db "Packet statistics version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  33.  db "This program is free software; see the file COPYING for details.",CR,LF
  34.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  35. crlf_msg    db    CR,LF,'$'
  36.  
  37. int_pkt    macro
  38.     pushf
  39.     cli
  40.     call    their_isr
  41.     endm
  42.  
  43. their_isr    dd    ?
  44. packet_int_no    db    60h,0,0,0
  45. packet_int_end    db    7fh,0,0,0
  46.  
  47. handle        dw    ?
  48.  
  49. bogus_type    db    0,0        ;totally bogus type code.
  50.  
  51. signature    db    'PKT DRVR',0
  52. signature_len    equ    $-signature
  53. usage_msg    db    "usage: pktstat <packet_int_no> [packet_int_no_end]",'$'
  54.  
  55. stat_names    db    "    pkt_in    pkt_out    byt_in    byt_out    err_in    err_out    pk_drop",CR,LF,'$'
  56. printed_names    db    0        ;haven't printed the names yet.
  57.  
  58. statistics_list    label    dword
  59. packets_in    dw    ?,?
  60. packets_out    dw    ?,?
  61. bytes_in    dw    ?,?
  62. bytes_out    dw    ?,?
  63. errors_in    dw    ?,?
  64. errors_out    dw    ?,?
  65. packets_dropped    dw    ?,?        ;dropped due to no type handler.
  66. statistics_count    equ    $ - statistics_list
  67.  
  68. check_packet_no:
  69.     or    word ptr [di+2],0
  70.     jne    usage_error
  71.     cmp    word ptr [di],60h
  72.     jb    usage_error
  73.     cmp    word ptr [di],7fh
  74.     ja    usage_error
  75.     ret
  76.  
  77.  
  78. usage_error:
  79.     mov    dx,offset usage_msg
  80. error:
  81.     mov    ah,9
  82.     int    21h
  83.     int    20h
  84.  
  85. start_1:
  86.     cld
  87.  
  88.     mov    dx,offset copyleft_msg
  89.     mov    ah,9
  90.     int    21h
  91.  
  92.     mov    si,offset phd_dioa+1
  93.  
  94.     mov    di,offset packet_int_no
  95.     call    get_number
  96.     jc    start_2            ;if they entered a number, change the default.
  97.     mov    word ptr packet_int_end+0,cx
  98.     mov    word ptr packet_int_end+2,bx
  99. start_2:
  100.     call    check_packet_no
  101.  
  102.     mov    di,offset packet_int_end
  103.     call    get_number
  104.  
  105.     call    check_packet_no
  106.  
  107.     call    skip_blanks
  108.     cmp    al,CR
  109.     jne    usage_error
  110.  
  111.     mov    al,packet_int_no    ;make sure they're in the right order.
  112.     cmp    al,packet_int_end
  113.     ja    usage_error
  114.  
  115. chk_loop:
  116.     call    chk_int
  117.     mov    al,packet_int_no
  118.     cmp    al,packet_int_end
  119.     jz    all_done
  120.     inc    packet_int_no        ; increment
  121.     jmp    chk_loop
  122. all_done:
  123.     mov    al,0
  124.     mov    ah,04ch
  125.     int    21h            ; exit with errorlevel 0
  126.  
  127. chk_int:
  128. ;check packet_int_no for a packet driver.  If there's one there, print
  129. ;the statistics and return nc.  If not, return cy.
  130.     mov    ah,35h            ;get their packet interrupt.
  131.     mov    al,packet_int_no
  132.     int    21h
  133.     mov    their_isr.offs,bx
  134.     mov    their_isr.segm,es
  135.  
  136.     lea    di,3[bx]
  137.     mov    si,offset signature
  138.     mov    cx,signature_len
  139.     repe    cmpsb
  140.     je    have_signature
  141.     stc
  142.     ret
  143. have_signature:
  144.  
  145.     push    ds
  146.     mov    ax,1ffh            ;driver_info
  147.     int_pkt
  148.     pop    ds
  149.     call    fatal_error
  150.  
  151.     mov    ah,2            ;access_type
  152.     mov    al,ch            ;their class from driver_info().
  153.     mov    bx,dx            ;their type from driver_info().
  154.     mov    dl,cl            ;their number from driver_info().
  155.     mov    cx,2            ;use a type length of 2.
  156.     mov    si,offset bogus_type
  157.     push    cs            ;es:di -> our receiver.
  158.     pop    es
  159.     mov    di,offset our_recv
  160.     int_pkt
  161.     call    fatal_error
  162.     mov    handle,ax
  163.  
  164.     mov    ah,24            ;get the statistics
  165.     mov    bx,handle
  166.     int_pkt
  167.     jc    bad
  168.     assume    ds:nothing
  169. ;ds:si now points to the statistics list.
  170.     mov    cx,statistics_count/2
  171.     mov    ax,cs
  172.     mov    es,ax
  173.     mov    di,offset statistics_list
  174.     rep    movsw
  175.     mov    ds,ax            ;restore ds to cs.
  176.  
  177.     cmp    printed_names,0        ;have we printed the names yet?
  178.     jne    did_print_names
  179.  
  180.     inc    printed_names
  181.     mov    dx,offset stat_names
  182.     mov    ah,9
  183.     int    21h
  184. did_print_names:
  185.  
  186.     mov    al,packet_int_no    ;print the packet interrupt number.
  187.     call    byteout
  188.     mov    al,'I'-40h        ;tab over.
  189.     call    chrout
  190.  
  191.     mov    bx,offset statistics_list
  192.     mov    cx,statistics_count/4
  193. print_stats:
  194.     mov    ax,[bx]
  195.     mov    dx,[bx+2]
  196.     push    bx
  197.     push    cx
  198.     call    decout
  199.     pop    cx
  200.     pop    bx
  201.     add    bx,4
  202.     mov    al,'I'-40h        ;tab over.
  203.     call    chrout
  204.     loop    print_stats
  205.  
  206.     mov    dx,offset crlf_msg
  207.     mov    ah,9
  208.     int    21h
  209.  
  210.     mov    ah,3            ;release_type
  211.     mov    bx,handle
  212.     int_pkt
  213.     call    fatal_error
  214.  
  215.     clc
  216.     ret
  217.  
  218.  
  219. bad:
  220.     push    cs
  221.     pop    ds
  222.     call    print_error
  223.  
  224.     mov    ah,3            ;release_type
  225.     mov    bx,handle
  226.     int_pkt
  227.     call    fatal_error
  228.  
  229.     int    20h
  230.  
  231.  
  232. our_recv:
  233.     or    ax,ax            ;first or second call?
  234.     jne    our_recv_1        ;second -- we ignore the packet
  235.     push    cs
  236.     pop    es
  237.     mov    di,offset our_buffer
  238. our_recv_1:
  239.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  240.  
  241.  
  242.     include    printea.asm
  243.  
  244.     assume    ds:code
  245.  
  246.     include    pkterr.asm
  247.     include    getnum.asm
  248.     include    skipblk.asm
  249.     include    getdig.asm
  250.     include    decout.asm
  251.     include    digout.asm
  252.     include    chrout.asm
  253.  
  254. our_buffer    label    byte
  255.  
  256. code    ends
  257.  
  258.     end    start
  259.